package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.WebConfigDao;
import ysq.xyg.model.WebConfig;
import ysq.xyg.service.WebConfigService;

import javax.annotation.Resource;
import java.util.List;


@Service("webConfigService")
public class WebConfigServiceImpl extends BaseServiceImpl<WebConfig> implements WebConfigService {

    @Resource
    private WebConfigDao webConfigDao;
    @Autowired
    public void setpictureDao(WebConfigDao webConfigDao) {
        this.baseDao = webConfigDao;
    }

    @Override
    public PageInfo<WebConfig> page(WebConfig webConfig, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        PageHelper.orderBy("sort desc");
        return new PageInfo<WebConfig>(list(webConfig));
    }

    @Override
    public List<WebConfig> list(WebConfig webConfig) {
        // 通用Example查询
        Example example = new Example(WebConfig.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(webConfig.getName())) {
            criteria.andLike("name", "%"+webConfig.getName()+"%");
        }
        example.setOrderByClause("sort desc");
        List<WebConfig> list = webConfigDao.selectByExample(example);
        return list;
    }
}
